﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SBACN.WebSite.Models;
using SBACN.WebSite.Code;
using System.Linq.Expressions;
using SBACN.WebSite.Common;

namespace SBACN.WebSite
{
    public partial class Message : MemberBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!IsLogin)
                {
                    Response.Redirect("index.aspx");
                }
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblValid.Visible = false;
            if (this.txt_valid.Text.Trim().ToLower() != Session["Message"].ToString().ToLower())
            {
                lblValid.Visible = true;
                return;
            }

            if (IsLogin)
            {
                TB_Feedback f = new TB_Feedback();
                f.UserIdentity = UserInfo.UserName;
                f.Title = txt_title.Text.Trim();
                f.Content = txt_Complain.Text.Trim();
                f.Status = 0;
                f.CreateDate = DateTime.Now;
                f.Type = "00050008";
				f.Memo = string.Empty;
                DAL.DALHelper.Instance.AddWithTransaction<TB_Feedback>(f);
                Page.ClientScript.RegisterStartupScript(GetType(), "show", "<script>ShowMessage();</script>");

                //发邮件
                if (!string.IsNullOrEmpty(UserInfo.EMail))
                {
                    Expression<Func<TB_SystemConfig, bool>> ff = (p => p.Type == "00090007" & p.Code == "1");
                    var resultR = DAL.DALHelper.Instance.GetFirstOrDefaultObject<TB_SystemConfig>(ff);
                    if (resultR != null && resultR.Status)
                    {
                        Mail.Instance.SendEMail(resultR.Name.Replace("$Name", UserInfo.UserName),
                        resultR.Value.Replace("$Name", UserInfo.UserName), UserInfo.EMail);
                    }
                }
            }
        }
    }
}